#pragma once
#include <iostream>
#include <pthread.h>

class Mutex
{
public:
    Mutex()
    {
        pthread_mutex_init(&_lock, nullptr);
    }
    void Lock()
    {
        pthread_mutex_lock(&_lock);
    }
    void UnLock()
    {
        pthread_mutex_unlock(&_lock);
    }
    ~Mutex()
    {
        pthread_mutex_destroy(&_lock);
    }

private:
    pthread_mutex_t _lock;
};

class Lock
{
public:
    Lock(Mutex *mutex)
        : _mutex(mutex)
    {
       _mutex->Lock();
    }
    ~Lock()
    {
        _mutex->UnLock();
    }

private:
    Mutex *_mutex;
};